2020-2021 Sunseeker Telemetry and Lighting System
adc12_a_ex4_repeatedSeq.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
76 //******************************************************************************
77 #include "driverlib.h"
78 
79 #define Num_of_Results 8
80 
81 volatile uint16_t A0results[Num_of_Results];
82 volatile uint16_t A1results[Num_of_Results];
83 volatile uint16_t A2results[Num_of_Results];
84 volatile uint16_t A3results[Num_of_Results];
85 
86 void main (void)
87 {
88  //Stop Watchdog Timer
89  WDT_A_hold(WDT_A_BASE);
90 
91  //Enable A/D channel inputs
92  GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
93  GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
94  GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
95  GPIO_PIN6 + GPIO_PIN7
96  );
97 
98  //Initialize the ADC12_A Module
99  /*
100  * Base address of ADC12_A Module
101  * Use internal ADC12_A bit as sample/hold signal to start conversion
102  * USE MODOSC 5MHZ Digital Oscillator as clock source
103  * Use default clock divider of 1
104  */
105  ADC12_A_init(ADC12_A_BASE,
106  ADC12_A_SAMPLEHOLDSOURCE_SC,
107  ADC12_A_CLOCKSOURCE_ADC12OSC,
108  ADC12_A_CLOCKDIVIDER_1
109  );
110 
111  ADC12_A_enable(ADC12_A_BASE);
112 
113  /*
114  * Base address of ADC12_A Module
115  * For memory buffers 0-7 sample/hold for 256 clock cycles
116  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
117  * Enable Multiple Sampling
118  */
119  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
120  ADC12_A_CYCLEHOLD_256_CYCLES,
121  ADC12_A_CYCLEHOLD_4_CYCLES,
122  ADC12_A_MULTIPLESAMPLESENABLE);
123 
124  //Configure Memory Buffers
125  /*
126  * Base address of the ADC12_A Module
127  * Configure memory buffer 0
128  * Map input A0 to memory buffer 0
129  * Vref+ = AVcc
130  * Vref- = AVss
131  * Memory buffer 0 is not the end of a sequence
132  */
133  ADC12_A_configureMemoryParam param0 = {0};
134  param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
135  param0.inputSourceSelect = ADC12_A_INPUT_A0;
136  param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
137  param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
138  param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
139  ADC12_A_configureMemory(ADC12_A_BASE ,&param0);
140 
141  /*
142  * Base address of the ADC12_A Module
143  * Configure memory buffer 1
144  * Map input A1 to memory buffer 1
145  * Vref+ = AVcc
146  * Vref- = AVss
147  * Memory buffer 1 is not the end of a sequence
148  *
149  */
150  ADC12_A_configureMemoryParam param1 = {0};
151  param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
152  param1.inputSourceSelect = ADC12_A_INPUT_A1;
153  param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
154  param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
155  param1.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
156  ADC12_A_configureMemory(ADC12_A_BASE ,&param1);
157  /*
158  * Base address of the ADC12_A Module
159  * Configure memory buffer 2
160  * Map input A2 to memory buffer 2
161  * Vref+ = AVcc
162  * Vref- = AVss
163  * Memory buffer 2 is not the end of a sequence
164  */
165  ADC12_A_configureMemoryParam param2 = {0};
166  param2.memoryBufferControlIndex = ADC12_A_MEMORY_2;
167  param2.inputSourceSelect = ADC12_A_INPUT_A2;
168  param2.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
169  param2.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
170  param2.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
171  ADC12_A_configureMemory(ADC12_A_BASE ,&param2);
172  /*
173  * Base address of the ADC12_A Module
174  * Configure memory buffer 3
175  * Map input A3 to memory buffer 3
176  * Vr+ = AVcc
177  * Vr- = AVss
178  * Memory buffer 3 IS the end of a sequence
179  */
180  ADC12_A_configureMemoryParam param3 = {0};
181  param3.memoryBufferControlIndex = ADC12_A_MEMORY_3;
182  param3.inputSourceSelect = ADC12_A_INPUT_A3;
183  param3.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
184  param3.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
185  param3.endOfSequence = ADC12_A_ENDOFSEQUENCE;
186  ADC12_A_configureMemory(ADC12_A_BASE ,&param3);
187 
188  //Enable memory buffer 3 interrupt
189  ADC12_A_clearInterrupt(ADC12_A_BASE,
190  ADC12IFG3);
191  ADC12_A_enableInterrupt(ADC12_A_BASE,
192  ADC12IE3);
193 
194  //Enable/Start first sampling and conversion cycle
195  /*
196  * Base address of ADC12_A Module
197  * Start the conversion into memory buffer 0
198  * Use the repeated sequence of channels
199  */
200  ADC12_A_startConversion(ADC12_A_BASE,
201  ADC12_A_MEMORY_0,
202  ADC12_A_REPEATED_SEQOFCHANNELS);
203 
204  //Enter LPM0, Enable interrupts
205  __bis_SR_register(LPM0_bits + GIE);
206  //For debugger
207  __no_operation();
208 }
209 
210 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
211 #pragma vector=ADC12_VECTOR
212 __interrupt
213 #elif defined(__GNUC__)
214 __attribute__((interrupt(ADC12_VECTOR)))
215 #endif
216 void ADC12ISR (void)
217 {
218  static uint16_t index = 0;
219 
220  switch (__even_in_range(ADC12IV,34)){
221  case 0: break; //Vector 0: No interrupt
222  case 2: break; //Vector 2: ADC overflow
223  case 4: break; //Vector 4: ADC timing overflow
224  case 6: break; //Vector 6: ADC12IFG0
225  case 8: break; //Vector 8: ADC12IFG1
226  case 10: break; //Vector 10: ADC12IFG2
227  case 12: //Vector 12: ADC12IFG3
228  //Move A0 results, IFG is cleared
229  A0results[index] =
230  ADC12_A_getResults(ADC12_A_BASE,
231  ADC12_A_MEMORY_0);
232  //Move A1 results, IFG is cleared
233  A1results[index] =
234  ADC12_A_getResults(ADC12_A_BASE,
235  ADC12_A_MEMORY_1);
236  //Move A2 results, IFG is cleared
237  A2results[index] =
238  ADC12_A_getResults(ADC12_A_BASE,
239  ADC12_A_MEMORY_2);
240  //Move A3 results, IFG is cleared
241  A3results[index] =
242  ADC12_A_getResults(ADC12_A_BASE,
243  ADC12_A_MEMORY_3);
244 
245  //Increment results index, modulo; Set BREAKPOINT here
246  index++;
247 
248  if (index == 8){
249  (index = 0);
250  }
251  case 14: break; //Vector 14: ADC12IFG4
252  case 16: break; //Vector 16: ADC12IFG5
253  case 18: break; //Vector 18: ADC12IFG6
254  case 20: break; //Vector 20: ADC12IFG7
255  case 22: break; //Vector 22: ADC12IFG8
256  case 24: break; //Vector 24: ADC12IFG9
257  case 26: break; //Vector 26: ADC12IFG10
258  case 28: break; //Vector 28: ADC12IFG11
259  case 30: break; //Vector 30: ADC12IFG12
260  case 32: break; //Vector 32: ADC12IFG13
261  case 34: break; //Vector 34: ADC12IFG14
262  default: break;
263  }
264 }
volatile uint16_t A1results[Num_of_Results]
volatile uint16_t A2results[Num_of_Results]
void main(void)
#define Num_of_Results
volatile uint16_t A3results[Num_of_Results]
void ADC12ISR(void)
volatile uint16_t A0results[Num_of_Results]
__no_operation()